package com.vgmobile.cucrever2.product.detail;

import java.util.ArrayList;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.vgmobile.cucrever2.R;

public class ImageDetailAdapter extends PagerAdapter {

	private ProductDetailActivity activity;
    private ArrayList<String> listImage;
    private LayoutInflater layoutInflater;
	
	public ImageDetailAdapter(ProductDetailActivity activity, ArrayList<String> listImage){
		this.activity = activity;
		this.listImage = listImage;
		layoutInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return listImage.size();
	}

	@Override
	public boolean isViewFromObject(View view, Object object) {
		// TODO Auto-generated method stub
		return (view == object);  
	}
	
	@Override
	public Object instantiateItem(ViewGroup container, int position) {
		View view = layoutInflater.inflate(R.layout.product_detail_image_item, null);
		ImageView imageView = (ImageView) view.findViewById(R.id.product_detail_imageview_viewpager);
		imageView.setOnClickListener(new OnClickListener() {
			public void onClick(View arg0) {
			
			}
		});
		activity.loadImage(imageView, listImage.get(position));
		((ViewPager)container).addView(view);	
		return view;
	}
	
	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		((ViewPager) container).removeView((View) object);
	}

}
